package org.sunshinebox.team.core.internalization;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

import org.sunshinebox.team.core.internalization.exception.UnknownSourceException;
import org.sunshinebox.team.core.internalization.exception.UnresolvedMessageException;

public class MessageResolver {
	
	Map<String, MessageSource> registratedSources = new HashMap<String, MessageSource>();
	
	//Test free
	public void registrateSource(String sourceId, MessageSource source){
		registratedSources.put(sourceId, source);
	}
	
	public String resolveMessage(Message message) throws UnknownSourceException, UnresolvedMessageException{
		MessageSource source = registratedSources.get(message.getSourceId());
		if (source == null)
			throw new UnknownSourceException();
		String body = source.getMessageById(message.getId());
		return MessageFormat.format(body, message.getArguments());
	}
	
}
